package com.example.testhiber.initPackage.business.utils;

import com.alibaba.fastjson.JSONObject;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * @version v1.0
 * @ProjectName: testhiber
 * @ClassName: DecryptUtil
 * @Description: TODO(一句话描述该类的功能)
 * @Author: fcy
 * @Date: 2020/7/21 0021 20:05
 */
public class DecryptUtil {

    // 解密
    public static String decrypt(String content, String sKey) {
        try {
            //实例化
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
            cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(sKey.getBytes(StandardCharsets.UTF_8), "AES"));
            byte[] encrypted = Base64.getDecoder().decode(content); // 先用base64解密
            byte[] original = cipher.doFinal(encrypted);
            return new String(original, StandardCharsets.UTF_8);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


}
